let app = getApp();
var siteinfo = require('../../siteinfo.js');
Page({
  data: {
    status: '介绍',
    chapterList:[]
  },

  onLoad: function (options) {
    this.setData({
      id:options.id,
      isTestScores: options.isTestScores
    })
    this.getCourseDetails()
    this.getChapterList()
  },
  onShow: function () {

  },
  /**
    * 切换标签
    */
  bindHeaderTap: function (e) {
    this.setData({
      status: e.target.dataset.status
    });
  },
  //获取课程详情数据
  getCourseDetails: function () {
    var _this = this
    app._get(siteinfo.selCourseDetails, {
      id: _this.data.id
    }, function (result) {
      _this.setData(result.data);
    })
  },
  //获取章节列表
  getChapterList: function () {
    var _this = this
    app._get(siteinfo.selChapterList, {
      id: _this.data.id
    }, function (result) {
      var chapterList = result.data
      chapterList.forEach(function(item,index){
        var resourceList = item.children;
        if(resourceList!=''){
          resourceList.forEach(function(item2,index2){
          })
      }
      _this.setData({
        chapterList:result.data,
        resourceList:resourceList
      });
      })
      
    })
  },
  //在线测试
  toTest: function (e) {
    wx.navigateTo({
      url: '/pages/practice/practice?chapterId=' + e.currentTarget.dataset.id,
    })
  },

  //模拟考试
  toExam: function (e) {
    wx.navigateTo({
      url: '/pages/exam/exam?courseId=' + this.data.id + "&type=" + e.currentTarget.dataset.type,
    })
  },
  
//播放
play:function(e){
  // let _this = this
  // let str = JSON.stringify(_this.data.chapterList);
  // console.log(str)
  wx.navigateTo({
   url: '/pages/videoPlay/videoPlay?chapterId=' + e.currentTarget.dataset.id + '&courseId=' + this.data.id+'&resourceId='+e.currentTarget.dataset.id,
  // url: '/pages/videoPlay/videoPlay?str=' + str,
  })

},
open: function (e) {
  var key = e.currentTarget.dataset.key;
  var val=e.currentTarget.dataset.value;
  key = key + '.isOpen';
  this.setData({
    [key]: !val
  });
},
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})